package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;

/**
 * @ClassName HtmlEditorDemo
 * @Description
 * @Author wangss
 * @date 2020.07.01 00:03
 * @Version 1.0
 */
public class HtmlEditorDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        AnchorPane an = new AnchorPane();

        HTMLEditor htmlEditor = new HTMLEditor();

        Button b1 = new Button("button1");
        Button b2 = new Button("button2");

        HBox hBox = new HBox(20);
        hBox.getChildren().addAll(b1, b2);

        AnchorPane.setTopAnchor(htmlEditor, 100d);
        AnchorPane.setLeftAnchor(htmlEditor, 50d);
        an.getChildren().addAll(hBox, htmlEditor);

        Scene scene = new Scene(an);
        primaryStage.setScene(scene);
        primaryStage.setHeight(800d);
        primaryStage.setWidth(1000d);
        primaryStage.setMinHeight(800d);
        primaryStage.setMinWidth(800d);
        primaryStage.setAlwaysOnTop(true);
        primaryStage.show();

        b1.setOnAction(event -> {
            htmlEditor.setHtmlText("Hello World");
        });

        htmlEditor.prefWidthProperty().bind(primaryStage.widthProperty().subtract(100d));
        htmlEditor.prefHeightProperty().bind(primaryStage.heightProperty().subtract(200d));
    }
}
